package com.aaa.hospital.ManagementEnd.controller;

import com.aaa.hospital.ManagementEnd.pojo.Check;
import com.aaa.hospital.ManagementEnd.service.Impl.CheckSerImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//补货审核页面
@Controller
@RequestMapping("/check")
public class CheckCon {
    @Autowired
    private CheckSerImpl checkSerImpl;
    @RequestMapping(value = "/selectAll",method = RequestMethod.GET)
    // 将java对象转为json格式的数据
    @ResponseBody
    //查询学生信息
    public String selectAll(){
        JSONObject json = new JSONObject();
        List<Check> data = checkSerImpl.queryAll();
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }

    //搜索框查询
    @RequestMapping(name="查询订单信息",value = "/select_id_ypName",method = RequestMethod.GET)
    @ResponseBody
    public String select_id_ypName(@Param("id") Integer id, @Param("ypname") String ypname){
        JSONObject json = new JSONObject();
        List<Check> data =checkSerImpl.select_id_ypName(id,ypname);
        Object objData=JSONObject.toJSON(data);
        json.put("code", 0);
        json.put("msg", "");
        json.put("count",data.size());
        json.put("data",objData);
        return json.toJSONString();
    }

    //提交补货订单
    @RequestMapping(value = "/insert",method = RequestMethod.GET)
    @ResponseBody
    private Map<String, Object> insert(Check check) {
        Date date=new Date();
        check.setStime(date);
        int result =checkSerImpl.insert(check);
        Map<String, Object> map = new HashMap<>();
        if (result > 0) {
            map.put("status", 1);
        } else {
            map.put("status", 0);
        }
        return map;
    }
    @RequestMapping(name="根据进货订单编号修改状态",value = "/updateZT", produces = "application/json;charset=UTF-8")
    @ResponseBody
    private String updateZT(Integer id) {
        checkSerImpl.updateZT(id);
        return JSON.toJSONString(true);
    }
}
